<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    //建一个map把每个值存进去 每次算差 如果map里有这个差返回没有返回null
    function fn(nums, target) {
        let map = new Map()
        for (let i = 0; i < nums.length; i++) {
            let left = target - nums[i]
            if (map.has(left)) {
                return [map.get(left), i]
            }
            map.set(nums[i], i)
        }
        return null
    }



</script>

</html>